SRC_DIR = ./src
BUILD_DIR = ./build
TAGET = $(BUILD_DIR)/fsnn

CC = g++
CFLAGS = -Wall
CFLAGS += -g

SRCS = $(shell find $(SRC_DIR) -name "*.cpp")
OBJS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
DEPS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.d,$(SRCS))
INCS = $(addprefix -I ,$(dir $(SRCS)))
INCS +=-I./json/single_include


SYSTEMC = ./libs/systemc-2.3.3
SYSC_LIB = -L$(SYSTEMC)/lib-linux64/
SYSC_INC = -I$(SYSTEMC)/include
SYSC_l = -lsystemc

LIBS += $(SYSC_LIB)
INCS += $(SYSC_INC)

all : $(TAGET)

$(BUILD_DIR)/%.d: $(SRC_DIR)/%.c
	@mkdir -p $(dir $@); \
	rm -f $@; \
	$(CC) -MM $< >$@.tmp; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.tmp > $@; \
	rm -f $@.tmp

$(BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(INCS) -c -o $@ $<

$(TAGET) : $(OBJS)
	@echo "building $@..."
	@mkdir -p $(dir $@)
	$(CC) $(LIBS) $(SYSC_l) -o $(TAGET) $(OBJS)

clean:
	@echo "clean..."
	rm -rf $(BUILD_DIR)

-include $(DEPS)
